/**
 * 
 */
package com.eis.persist.model.function;

import java.io.Serializable;
import java.util.Map;

import com.eis.persist.model.base.BasePersist;
import com.eis.thirdsys.connector.datatype.eissystype.SchemaDefine;

/**
 * @author panwei01
 *
 */
public class PersistFunctionSchema extends BasePersist implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2054024049979350824L;

	public PersistFunctionSchema() {
		super();
	}
	
	public PersistFunctionSchema(Map<String, Object> record) {
		super();
		this.id = (Integer) record.get("id");
		this.functionDBID = (Integer) record.get("functionDBID");
		this.fieldName = (String) record.get("fieldName");
		this.fieldLength = (Integer) record.get("fieldLength");
		this.fieldType = (String) record.get("fieldType");
		this.isExt = ((Integer) record.get("isExt") != 0);
		this.defaultDisplayName = (String) record.get("defaultDisplayName");
		this.customizeDisplayName = (String) record.get("customizeDisplayName");
	}
	
	public PersistFunctionSchema(int functionDBID, Map<String, Object> sapSchema) {
		this.functionDBID = functionDBID;
		this.fieldName = ((String) sapSchema.get(SchemaDefine.FIELDNAME.name())).trim();
		if (sapSchema.get(SchemaDefine.LENG.name()) != null) {
			this.fieldLength = new Integer((String)sapSchema.get(SchemaDefine.LENG.name()));
		}
		
		this.fieldType = ((String) sapSchema.get(SchemaDefine.DATATYPE.name())).trim();
		
		if (sapSchema.get(SchemaDefine.SCRTEXT_M.name()) != null) {
			this.defaultDisplayName = (String) sapSchema.get(SchemaDefine.SCRTEXT_M.name());
		}
	}
	
	private int id;
	private int functionDBID;
	private String fieldName;
	private int fieldLength;
	private String fieldType;
	private boolean isExt;
	private String defaultDisplayName;
	private String customizeDisplayName;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getFunctionDBID() {
		return functionDBID;
	}
	public void setFunctionDBID(int functionDBID) {
		this.functionDBID = functionDBID;
	}
	public String getFieldName() {
		if (fieldName == null) fieldName = "";
		return fieldName.trim();
	}
	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}
	public int getFieldLength() {
		return fieldLength;
	}
	public void setFieldLength(int fieldLength) {
		this.fieldLength = fieldLength;
	}
	public String getFieldType() {
		if (fieldType == null) fieldType = "";
		return fieldType.trim();
	}
	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}
	public boolean isExt() {
		return isExt;
	}
	public void setExt(boolean isExt) {
		this.isExt = isExt;
	}
	public String getDefaultDisplayName() {
		if (defaultDisplayName == null) defaultDisplayName = "";
		return defaultDisplayName.trim();
	}
	public void setDefaultDisplayName(String defaultDisplayName) {
		this.defaultDisplayName = defaultDisplayName;
	}
	public String getCustomizeDisplayName() {
		if (customizeDisplayName == null) customizeDisplayName = "";
		return customizeDisplayName.trim();
	}
	public void setCustomizeDisplayName(String customizeDisplayName) {
		this.customizeDisplayName = customizeDisplayName;
	}
	
	public boolean equals(Object obj) {
		return (obj instanceof PersistFunctionSchema && this.fieldName.equalsIgnoreCase(((PersistFunctionSchema)obj).getFieldName()));
	}
}